package com.yugao.fintech.antelope.system.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yugao.fintech.antelope.system.mapper.SysRoleDeptRelMapper;
import com.yugao.fintech.antelope.system.model.entity.SysRoleDeptRel;
import com.yugao.fintech.framework.assistant.utils.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;


@Component
public class SysRoleDeptRelManager {
    @Autowired
    private SysRoleDeptRelMapper roleDeptRelMapper;

    /**
     * 通过角色ID删除角色和部门关联
     *
     * @param roleId 角色ID
     * @return 结果
     */
    public int deleteByRoleId(Long roleId) {
        if (Objects.isNull(roleId)) {
            return 0;
        }
        LambdaQueryWrapper<SysRoleDeptRel> wrapper = Wrappers.<SysRoleDeptRel>lambdaQuery()
                .eq(SysRoleDeptRel::getRoleId, roleId);
        return roleDeptRelMapper.delete(wrapper);
    }

    public boolean deleteByRoleIds(List<Long> roleIds) {
        if (CollectionUtils.isEmpty(roleIds)) {
            return true;
        }
        LambdaQueryWrapper<SysRoleDeptRel> wrapper = SysRoleDeptRel.lqw()
                .in(SysRoleDeptRel::getRoleId, roleIds);
        return roleDeptRelMapper.delete(wrapper) > 0;
    }

    public void deleteByDeptIds(List<Long> deptIds) {
        if (CollectionUtils.isEmpty(deptIds)) {
            return;
        }
        LambdaQueryWrapper<SysRoleDeptRel> lqw = SysRoleDeptRel.lqw().in(SysRoleDeptRel::getDeptId, deptIds);
        roleDeptRelMapper.delete(lqw);
    }
}
